package com.ruoyi.web.controller.teacher;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.BasisCamp;
import com.ruoyi.service.IBasisCampService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 阵营Controller
 * 
 * @author wangzebing
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/camp")
public class BasisCampController extends BaseController
{
    @Autowired
    private IBasisCampService basisCampService;

    /**
     * 查询阵营列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BasisCamp basisCamp)
    {
        startPage();
        List<BasisCamp> list = basisCampService.selectBasisCampList(basisCamp);
        return getDataTable(list);
    }

    /**
     * 导出阵营列表
     */
    @Log(title = "阵营", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasisCamp basisCamp)
    {
        List<BasisCamp> list = basisCampService.selectBasisCampList(basisCamp);
        ExcelUtil<BasisCamp> util = new ExcelUtil<BasisCamp>(BasisCamp.class);
        util.exportExcel(response, list, "阵营数据");
    }

    /**
     * 获取阵营详细信息
     */
    @GetMapping(value = "/{campId}")
    public AjaxResult getInfo(@PathVariable("campId") Long campId)
    {
        return success(basisCampService.selectBasisCampByCampId(campId));
    }

    /**
     * 新增阵营
     */
    @Log(title = "阵营", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasisCamp basisCamp)
    {
        basisCamp.setType(basisCamp.getCampName());
        return toAjax(basisCampService.insertBasisCamp(basisCamp));
    }

    /**
     * 修改阵营
     */
    @Log(title = "阵营", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasisCamp basisCamp)
    {
        return toAjax(basisCampService.updateBasisCamp(basisCamp));
    }

    /**
     * 删除阵营
     */
    @Log(title = "阵营", businessType = BusinessType.DELETE)
	@DeleteMapping("/{campIds}")
    public AjaxResult remove(@PathVariable Long[] campIds)
    {
        return toAjax(basisCampService.deleteBasisCampByCampIds(campIds));
    }
}
